package br.com.android.games.daedal;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Criar um {@link TextView} inclinado
 * 
 * @since 2013
 * @author <a href="mailto:fernando.schindler@gmail.com">Fernando Schindler</a>
 */
public class SlopingTextView extends TextView {
	
	private float angle = -25;

	/**
	 * Criar umm label inclinado
	 * 
	 * @param context
	 * @param attrs
	 */
	public SlopingTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
				  R.styleable.SlopingTextView, 0, 0);
		try {
			angle = a.getFloat(R.styleable.SlopingTextView_angle, angle);
		} finally {
			a.recycle();
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.TextView#onMea(int)Math.cos(a)*sure(int, int)
	 */
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, widthMeasureSpec);
	} 

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.TextView#onDraw(android.graphics.Canvas)
	 */
	@Override
	protected void onDraw(Canvas canvas) { 
		// Save the current matrix
		canvas.save();
		// translate
		canvas.translate(0, this.getHeight()-getTextSize());
		// Rotate this View at its center
		canvas.rotate(angle, 0, 0);
		// Draw it
		super.onDraw(canvas);
		// Restore to the previous matrix
		canvas.restore();
	}
}
